home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 741 / rkrm_devices / rkrm_devices.lha / Resources / Read_BattClock.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  4KB  |  114 lines

  1. /*
  2.  * Copyright (c) 1992 Commodore-Amiga, Inc.
  3.  * 
  4.  * This example is provided in electronic form by Commodore-Amiga, Inc. for 
  5.  * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition, 
  6.  * published by Addison-Wesley (ISBN 0-201-56775-X).
  7.  * 
  8.  * The "Amiga ROM Kernel Reference Manual: Devices" contains additional 
  9.  * information on the correct usage of the techniques and operating system 
  10.  * functions presented in these examples.  The source and executable code 
  11.  * of these examples may only be distributed in free electronic form, via 
  12.  * bulletin board or as part of a fully non-commercial and freely 
  13.  * redistributable diskette.  Both the source and executable code (including 
  14.  * comments) must be included, without modification, in any copy.  This 
  15.  * example may not be published in printed form or distributed with any
  16.  * commercial product.  However, the programming techniques and support
  17.  * routines set forth in these examples may be used in the development
  18.  * of original executable software products for Commodore Amiga computers.
  19.  * 
  20.  * All other rights reserved.
  21.  * 
  22.  * This example is provided "as-is" and is subject to change; no
  23.  * warranties are made.  All use is at your own risk. No liability or
  24.  * responsibility is assumed.
  25.  *
  26.  *****************************************************************************
  27.  *
  28.  *
  29.  * Read_BattClock.c
  30.  *
  31.  * Example of reading the BattClock and converting its output to
  32.  * a useful measure of time by calling the Amiga2Date() utility function.
  33.  *
  34.  * Compile with SAS 5.10  lc -b1 -cfistq -v -y -L
  35.  *
  36.  * Run from CLI only
  37.  */
  38.  
  39. #include <exec/types.h>
  40. #include <dos/dos.h>
  41. #include <utility/date.h>
  42. #include <resources/battclock.h>
  43.  
  44. #include <clib/exec_protos.h>
  45. #include <clib/alib_protos.h>
  46. #include <clib/battclock_protos.h>
  47. #include <clib/utility_protos.h>
  48.  
  49. #include <stdio.h>
  50.  
  51. #ifdef LATTICE
  52. int CXBRK(void) { return(0); }  /* Disable SAS CTRL/C handling */
  53. int chkabort(void) { return(0); }  /* really */
  54. #endif
  55.  
  56. VOID main(VOID);
  57.  
  58. struct Library *UtilityBase = NULL;
  59. struct Library *BattClockBase;
  60.  
  61. VOID main(VOID)
  62. {
  63. UBYTE *Days[] ={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
  64. UBYTE *Months[] = {"January","February","March","April","May","June",
  65.                    "July","August","September","October","November","December"};
  66. UBYTE *ampm;
  67. ULONG AmigaTime;
  68.  
  69. struct ClockData MyClock;
  70.  
  71. if (UtilityBase = (struct Library *)OpenLibrary("utility.library",33))
  72.     {
  73.     if (BattClockBase= OpenResource(BATTCLOCKNAME))
  74.         {
  75.         /* Get number of seconds till now */
  76.         AmigaTime = ReadBattClock();
  77.  
  78.         /* Convert to a ClockData structure */
  79.         Amiga2Date(AmigaTime,&MyClock);
  80.  
  81.         printf("\nRobin, tell everyone the BatDate and BatTime");
  82.  
  83.         /* Print the Date */
  84.         printf("\n\nOkay Batman, the BatDate is ");
  85.         printf("%s, %s %d, %d",Days[MyClock.wday],Months[MyClock.month-1],
  86.                                MyClock.mday,MyClock.year);
  87.  
  88.         /* Convert military time to normal time and set AM/PM */
  89.         if (MyClock.hour < 12)
  90.             ampm = "AM";        /* hour less than 12, must be morning */
  91.         else
  92.             {
  93.             ampm = "PM";         /* hour greater than 12,must be night */
  94.             MyClock.hour -= 12;  /* subtract the extra 12 of military */
  95.             };
  96.  
  97.         if (MyClock.hour == 0)
  98.             MyClock.hour = 12;   /* don't forget the 12s */
  99.  
  100.         /* Print the time */
  101.         printf("\n             the BatTime is ");
  102.         printf("%d:%02d:%02d %s\n\n",MyClock.hour,MyClock.min,MyClock.sec,ampm);
  103.         }
  104.     else
  105.        printf("Error: Unable to open the %s\n",BATTCLOCKNAME);
  106.  
  107.     /* Close the utility library */
  108.     CloseLibrary(UtilityBase);
  109.     }
  110.  
  111. else
  112.     printf("Error: Unable to open utility.library\n");
  113. }
  114.